package com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.ui.homedoctor;

import android.content.Context;
import android.content.Intent;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.ActivityDoctorInfor;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.ActivityMedicalCaseReview;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.doctor.ActivityMedicineCompleteDoctor;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.ActivityMedicineService;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.doctor.ActivityMedicineInforDoctor;
import com.example.ai_basedintelligentdiagnosisandtreatmentofchildren.activity.doctor.ActivityPatientInformation;

public class HomeDoctorViewModel extends ViewModel {

    private Context context;

    public HomeDoctorViewModel() {

    }

    public HomeDoctorViewModel(Context context) {
        this.context = context;
    }

    public void performSearch(String query) {
        // 这里添加搜索逻辑，例如调用网络请求获取搜索结果
        // 可以使用 LiveData 通知 Fragment 更新 UI
        System.out.println("Performing search with query: " + query);
    }

    public void navigate(Context fromContext, Class<? extends Context> toContext) {
        Intent intent = new Intent(fromContext, toContext);
        fromContext.startActivity(intent);
    }

    public void onButtonClicked(int buttonId) {
        switch (buttonId) {
            case 1:
                break;

            case 2:
                // 处理按钮 2 的点击事件
                navigate(context, ActivityMedicalCaseReview.class);
                break;

            case 3:
                // 处理按钮 3 的点击事件
                navigate(context, ActivityDoctorInfor.class);
                break;

            case 4:
                break;

            case 5:
                break;

            case 6:
                // 处理按钮 6 的点击事件
                navigate(context, ActivityMedicineService.class);
                break;

            case 7:
                // 处理按钮 7 的点击事件
                navigate(context, ActivityMedicineInforDoctor.class);
                break;

            case 8:
                // 处理按钮 8 的点击事件
                navigate(context, ActivityPatientInformation.class);
                break;

            case 9:
                // 处理按钮 9 的点击事件
                navigate(context, ActivityMedicineCompleteDoctor.class);
                break;

            default:
                break;
        }
    }

    public static class Factory implements ViewModelProvider.Factory {
        private final Context context;

        public Factory(Context context) {
            this.context = context;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T extends ViewModel> T create(Class<T> modelClass) {
            if (modelClass.isAssignableFrom(HomeDoctorViewModel.class)) {
                return (T) new HomeDoctorViewModel(context);
            }
            throw new IllegalArgumentException("Unknown ViewModel class");
        }
    }
}